package com.zmn.plat.services.impl.servcateory;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.servcategory.CategoryFaultImage;
import com.zmn.plat.model.entity.servcategory.CategoryFaultImageQuery;
import com.zmn.plat.persistence.interfaces.servcategory.CategoryFaultImageDao;
import com.zmn.plat.services.interfaces.servcategory.CategoryFaultImageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 后端产品分类-故障图片接口实现类
 *
 * @author yangshuangping
 * @since  2021/11/18 18:37
 */
@Slf4j
@Service
public class CategoryFaultImageServiceImpl implements CategoryFaultImageService {

    private static final String TAG = "后端产品分类-故障图片基础服务接口";

    @Resource
    private CategoryFaultImageDao categoryFaultImageDao;

    @Override
    public CategoryFaultImage findById(Integer faultId) {

        if (Objects.isNull(faultId)) {
            log.error("[{}],根据id查询数据faultId为null", TAG);
            return null;
        }
        return categoryFaultImageDao.findById(faultId);
    }

    @Override
    public List<CategoryFaultImage> listByIds(List<Integer> faultIds) {

        if (CollectionUtils.isEmpty(faultIds)) {
            log.error("[{}],按条件查询数据,faultIds为null", TAG);
            return null;
        }
        return categoryFaultImageDao.listByIds(faultIds);
    }

    @Override
    public List<CategoryFaultImage> listByQuery(CategoryFaultImageQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return categoryFaultImageDao.listByQuery(query);
    }

    @Override
    public List<CategoryFaultImage> listPageByQuery(CategoryFaultImageQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(categoryFaultImageDao.countByQuery(query));
        return categoryFaultImageDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(CategoryFaultImageQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return categoryFaultImageDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(CategoryFaultImage categoryFaultImage) {

        if (Objects.isNull(categoryFaultImage.getFaultId())){
            log.error("[{}],根据id修改数据,categoryFaultImage为null", TAG);
            return null;
        }
        return categoryFaultImageDao.updateByKey(categoryFaultImage);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
            categoryFaultImageDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(CategoryFaultImage categoryFaultImage) {

        if (Objects.isNull(categoryFaultImage)) {
            log.error("[{}],新增数据,categoryFaultImage为null", TAG);
            return null;
        }
        return categoryFaultImageDao.insert(categoryFaultImage);
    }

    @Override
    public void insertBatch(List<CategoryFaultImage> list) {

        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
            categoryFaultImageDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Integer faultId) {

        if (Objects.isNull(faultId)) {
            log.error("[{}],根据id删除数据,faultId为null", TAG);
            return null;
        }
        return categoryFaultImageDao.deleteByKey(faultId);
    }
    @Override
    public Integer deleteByKeys(List<Integer> ids) {

        if (CollectionUtil.isNullOrEmpty(ids)) {
            log.error("[{}],根据id删除数据,faultId为null", TAG);
            return null;
        }
        return categoryFaultImageDao.deleteByKeys(ids);
    }

}